﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using HellCook.Model;

namespace HellCook.WinApp_WPF.IngredientManager.IngredientFunctionality
{
    /// <summary>
    /// Interaction logic for SearchIngredient.xaml
    /// </summary>
    public partial class SearchIngredient : Window
    {
        public SearchIngredient()
        {
            InitializeComponent();
            DameTodosLosIngrediente();
        }

        private void DameTodosLosIngrediente()
        {
            this.dataGrid_ResultSearch.ItemsSource = HellCook.Business.Ingrediente_Buscador.ObtenerTodosLosIngredientes();
        }

        private void textBox_NameIngredient_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (String.IsNullOrEmpty(this.textBox_NameIngredient.Text))
            {
                DameTodosLosIngrediente();
            }
            else
            {
                this.dataGrid_ResultSearch.ItemsSource = null;
                this.dataGrid_ResultSearch.ItemsSource = HellCook.Business.Ingrediente_Buscador.ObtenerTodosLosIngredientesSimilarA(this.textBox_NameIngredient.Text);
            }
        }

        private void dataGrid_ResultSearch_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            
        }

        private void ModificarIngrediente(object sender, MouseButtonEventArgs e)
        {
            if (this.dataGrid_ResultSearch.SelectedIndex >= 0)
            {
                MessageBoxResult result;
                result = MessageBox.Show("¿Desea Modificar el ingrediente?", "Mensaje", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    Ingrediente nuevo;
                    nuevo = (Ingrediente)this.dataGrid_ResultSearch.SelectedItem;
                    Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente modificar = new Ingrediente_Administrador.IngredientFunctionality.ModificarIngrediente(nuevo);
                    modificar.ShowDialog();
                }
                this.textBox_NameIngredient.Text = "";
            }
        }
    }
}
